package overall

import "github.com/gin-gonic/gin"

/*
 解除跨域中间件

 作用：
  为所有接口解除前端跨域限制
*/
// ————————————————————————————————————————————————————————————————————————————————————————————————————
func OpenCrossDomain() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
		ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token")
		ctx.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
		ctx.Writer.Header().Set("Access-Control-Max-Age", "172800")
		ctx.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
		ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true")

		//执行后续中间件
		//--------------------------------------------------------------------------------------------------------------------------------------------------------------
		ctx.Next()
	}
}
